package org.squarecap.apps.eventcompanion.domain;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

import javax.validation.constraints.NotNull;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.persistence.CascadeType;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.Future;

import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

@RooJavaBean
@RooToString
@RooJpaActiveRecord(inheritanceType = "JOINED")
public abstract class Evento {

    /**
     */
    @NotNull
    private String titulo;

    /**
     */
    @ManyToOne
    private Tema tema;

    /**
     */
    @ManyToOne
    private Conferencista conferencista;

    /**
     */
    @ManyToOne
    private Asistente asistente;

    /**
     */
    @ManyToOne
    private Sala sala;

    /**
     */
    @Future
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    private Calendar fechaYHoraInicio;

    /**
     */
    @Min(0L)
    @Max(90L)
    private int duracion;

    /**
     */
    @NotNull
    @Min(0L)
    private int cupoMax;

    /**
     */
    @Future
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "M-")
    private Date inicioInsc;

    /**
     */
    @Future
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "M-")
    private Date finInsc;

    /**
     */
    @ManyToOne
    private Congreso congreso;

    public Calendar getFechaYHoraFin() {
        Calendar cal = new GregorianCalendar();
        cal.setTime(this.fechaYHoraInicio.getTime());
    	cal.add(Calendar.MINUTE, this.duracion);
        return cal;
    }

}
